<?php
namespace Admin\Controller;

use Think\Controller;

class HetongController extends Controller
{

    public function index()
    {sess();
        $cust = M('Hetong');
        $map = _search('Hetong');
        $map['uid'] = session('uid');
        $count = $cust->where($map)->count();
        $Page = getpage($count, 5); // 实例化分页类 传入总记录数
        $show = $Page->show(); // 分页显示输出
        $list = $cust->where($map)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();
        $this->assign('list', $list);
        $this->assign('page', $show);
        updateTime();
        $this->display();
    }

    public function outxls()
    {sess();
        $model = M('Hetong');
        $map = _search("Hetong");
        $map['uid'] = session('uid');
        $list = $model->where($map)
            ->field('id,title,addtime,jcname,yikai,weishou,jine,yishou,fukuan,name,uname,dqrq,updatetime')
            ->select();
        $headArr = array(
            'ID',
            '合同名称',
            '签约日期',
            '客户名称',
            '已开票',
            '未收款',
            '合同金额',
            '已收款',
            '已付款',
            '业务员',
            '添加人',
            '到期日期',
            '更新时间'
        );
        $filename = '合同管理';
        xlsout($filename, $headArr, $list);
        updateTime();
    }

    public function add()
    {sess();
        if (IS_POST) {
            if (add("Hetong")) {
                $this->assign('zt','添加成功！');
            } else {
                $this->assign('zt','添加失败！');
            }
        }
        updateTime();
        $this->display();
    }

    public function edit()
    {sess();
        $model = M('Hetong');
        $Rs = $model->getById(I('get.id'));
        $this->assign('Rs', $Rs);
        if (IS_POST) {
            if (edit("Hetong")) {
                $this->assign('zt','编辑成功！');
            } else {
                $this->assign('zt','编辑失败！');
            }
        }
        updateTime();
        $this->display();
    }

    public function del()
    {sess();
        if (del("Hetong")) {
            $this->assign('zt','删除成功！');
        } else {
            $this->assign('zt','删除失败！');
        }
        updateTime();
        $this->display('Hetong/index');
    }

    public function view()
    {sess();
        $model = M('Hetong');
        $Rs = $model->getByid(I('get.id'));
        $this->assign('Rs', $Rs);
        updateTime();
        $this->display();
    }
}